<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图1</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        ul {
            list-style: none;
        }
        .carousel {
            position: relative;
            width: 600px;
            height: 360px;
            border: 1px solid #000;
            margin: 100px auto;
        }
        .carousel ul li {
            position: absolute;
            top: 0;
            width: 150px;
            height: 360px;
            transform-style: preserve-3d;
            /* perspective: 5000px; */
            transition: all 1s ease 0s;

        }
        .carousel ul li:nth-child(1) {
            left: 0;
        }
        .carousel ul li:nth-child(2) {
            left: 150px;
        }
        .carousel ul li:nth-child(3) {
            left: 300px;
        }
        .carousel ul li:nth-child(4) {
            left: 450px;
        }

        .carousel ul li div {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-size: 600px 360px;
        }
        /* 设置每个 li 标签下面所有 div 的背景图片 */
        .carousel ul li div:nth-child(1) {
            background-image: url(images/pic1.jpg);
            transform: rotateX(0deg) translateZ(180px);
        }
        .carousel ul li div:nth-child(2) {
            background-image: url(images/pic2.jpg);
            transform: rotateX(90deg) translateZ(180px);
        }
        .carousel ul li div:nth-child(3) {
            background-image: url(images/pic3.jpg);
            transform: rotateX(180deg) translateZ(180px);
        }
        .carousel ul li div:nth-child(4) {
            background-image: url(images/pic4.jpg);
            transform: rotateX(270deg) translateZ(180px);
        }

        /* 不同 li 标签下 div 的样式 */
        .carousel ul li:nth-child(1) div {
            background-position: 0 0;
        }
        .carousel ul li:nth-child(2) div {
            background-position: -150px 0;
        }
        .carousel ul li:nth-child(3) div {
            background-position: -300px 0;
        }
        .carousel ul li:nth-child(4) div {
            background-position: -450px 0;
        }

        .btn {
            display: block;
            width: 100px;
            height: 50px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="carousel">
        <ul>
            <li>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </li>
            <li>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </li>
            <li>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </li>
            <li>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </li>
        </ul>
    </div>
    <input type="button" value="下一张" class="btn">
    <script src="JS/jquery-1.12.4.min.js"></script>
    <script>
        var $btn = $('.btn');
        var $lis = $('.carousel ul li');
        var sem = 0
    
        // 给事件添加一把锁，用于防骚扰
        var lock = false;
        // 添加点击事件
        $btn.click(function() {
          // 先判断锁的状态
          if (lock) return;
          // 一旦动画开始，就上锁
          lock = true;
          sem -= 90;
          $lis.css({
            "transform": "rotateX("+sem+"deg)"
          });
          // 动画执行完成时，解除锁
          var timeout = (1 + 0.1 * $lis.length) * 1000;
          setTimeout(function() {
            lock = false;
          }, timeout);
        })
      </script>
</body>
</html>